﻿using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Data_Account : Data
    {
        #region[Account_Insert]
        public void Account_Insert(Account data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Account_Insert", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Password", data.Password);
                cmd.Parameters.Add("@Name", data.Name);
                cmd.Parameters.Add("@Role", data.Role);
                cmd.Parameters.Add("@Status", data.Status);

                cmd.ExecuteNonQuery();
            }

        }
        #endregion

        #region[Account_Update_Pass]
        public void Account_Update_Pass(Account data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Account_Update_Pass", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Password", data.Password);
                cmd.ExecuteNonQuery();
            }

        }
        #endregion

        #region[Account_Update_Info]
        public void Account_Update_Info(Account data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_User_Update_Info", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Name", data.Name);
                cmd.Parameters.Add("@Role", data.Role);
                cmd.Parameters.Add("@Status", data.Status);

                cmd.ExecuteNonQuery();
            }

        }
        #endregion

        #region[Account_GetByAll]
        public DataTable Account_GetByAll(Account data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Account_GetByAll", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }

        }
        #endregion

        #region [Account_CheckLogin]
        public bool Account_CheckLogin(string username, string pass)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Account_CheckLogin", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", username);
                cmd.Parameters.Add("@Password", pass);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                bool check = true;
                if (dt.Rows.Count > 0)
                {
                    return check = true;
                }
                else
                {
                    return check = false;
                }
            }
        }
        #endregion
    }
}
